from basic import file2fullMatrix,autoNorm,simplePCA
import pandas as pd
from pandas.plotting import parallel_coordinates
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
from matplotlib.colors import ListedColormap
from mpl_toolkits.mplot3d import Axes3D



def colorGen(numb):	                          #把数字变成对应的颜色
	if numb=='0':
		return 'b'

	if numb=='1':
		return 'orange'



def showTwoDimen(filename):   #对某两个维度画散点图
	mat,tag,feature_name=file2fullMatrix(filename)
	mat=autoNorm(mat)

	mat_copy=simplePCA(mat,2)

	color=[colorGen(i) for i in tag]

	dimen1=mat[:,0]
	# min_x=np.min(dimen1,axis=0)
	# max_x=np.max(dimen1,axis=0)


	dimen2=mat[:,1]
	# min_y=np.min(dimen2,axis=0)
	# max_y=np.max(dimen2,axis=0)	


	fig1=plt.figure()
	ax=plt.subplot(1,1,1)
	# ax.set_xlim(min_x,max_x)
	# ax.set_ylim(min_y,max_y)


	ax.scatter(dimen1,dimen2,color=color,alpha=0.4)

	line1=mlines.Line2D([],[],color="b",marker='o',linestyle='',label='healthy')
	line2=mlines.Line2D([],[],color='orange',marker='o',linestyle='',label='unhealthy')

	plt.legend(handles=[line1,line2])
	plt.tight_layout()
	plt.show()




def showThreeDimen(filename):                  #对三个维度画图
	mat,tag,feature_name=file2fullMatrix(filename)
	mat=autoNorm(mat)

	mat_copy=simplePCA(mat,3)

	color=[colorGen(i) for i in tag]

	dimen1=mat[:,0]
	dimen2=mat[:,1]
	dimen3=mat[:,2]



	fig=plt.figure()
	ax=fig.add_subplot(111,projection='3d')


	ax.scatter(dimen1,dimen2,dimen3,color=color,alpha=0.4)

	line1=mlines.Line2D([],[],color="b",marker='o',linestyle='',label='healthy')
	line2=mlines.Line2D([],[],color='orange',marker='o',linestyle='',label='unhealthy')

	plt.legend(handles=[line1,line2])
	plt.tight_layout()
	plt.show()


def showXDimen(filename,x):                          #多维画图
	mat,tag,feature_name=file2fullMatrix(filename)
	mat=autoNorm(mat)
	mat_copy=simplePCA(mat,x)

	# target=["feature "+str(i) for i in range(x)]
	# print(feature_name)
	
	man=200          #选几个人
	
	data_dict=dict()
	for i in range(x):
		data_dict["f"+str(i)]=mat[:man, i]
	data_dict["tags"]=tag[:man]
	pd_data=pd.DataFrame(data_dict)
	
	fig=plt.figure()
	parallel_coordinates(pd_data,"tags",color=('#87A0FF','orange'),alpha=0.4)

	plt.tight_layout()
	plt.show()






if __name__=='__main__':
	filename="pd_speech_features.csv"
	showXDimen(filename,10)

